package plugins

import (
	"strings"

	"github.com/quarkcloudio/quark-go/v2/pkg/builder"
	authHandle "github.com/wsl/hi-go/plugins/middleware/authHandle"
	errorHandle "github.com/wsl/hi-go/plugins/middleware/errorHandle"
	verificationToken "github.com/wsl/hi-go/plugins/middleware/verificationToken"
)

type CustomHandle struct{}

// 创建一个全局的处理函数包装器
func (p *CustomHandle) GlobalCustomHandler(next builder.Handle) builder.Handle {
	return func(c *builder.Context) error {
		routePath := c.Path()
		if strings.Contains(routePath, "api/member") {
			return (&errorHandle.ErrorHandle{}).GlobalErrorHandler((&authHandle.AuthHandle{}).GlobalAuthHandler((&verificationToken.VerificationTokenHandle{}).VerificationTokenHandler(next)))(c)
		} else {
			return (&errorHandle.ErrorHandle{}).GlobalErrorHandler(next)(c)
		}
	}
}
